package com.iwords.service.ao.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.iwords.service.IWordsSearchServiceLocal;
import com.iwords.service.SentencesService;
import com.iwords.service.SentencesServiceLocal;
import com.iwords.service.object.ExamSentencesEntity;
import com.iwords.service.object.HotSentencesEntity;
import com.iwords.service.persistence.ExamSentencesPersistence;
import com.iwords.service.persistence.HotSentencesPersistence;

@Stateless
public class SentencesServiceImpl implements SentencesService, SentencesServiceLocal {

	@EJB
	private ExamSentencesPersistence examSentencesPersistence;
	@EJB
	private HotSentencesPersistence  hotSentencesPersistence;
	@EJB
	private IWordsSearchServiceLocal iWordsSearchService;
	private static final Log log=LogFactory.getLog(SentencesServiceImpl.class);

	@SuppressWarnings("unchecked")
	public List<ExamSentencesEntity> getHotSentences(Long wordid) {

		List<ExamSentencesEntity> resultList = new ArrayList<ExamSentencesEntity>();
		try {
			List<HotSentencesEntity> hotList = hotSentencesPersistence.getHotListByWordId(wordid);
			for (HotSentencesEntity hot : hotList) {
				resultList.add(examSentencesPersistence.getSentenceById(hot.getSentenceid()));
			}
			return resultList;

		} catch (Exception e) {
			log.error("查询热门句子出错", e);

		}
		return Collections.EMPTY_LIST;
	}

	@SuppressWarnings("unchecked")
	public List<ExamSentencesEntity> getAllSentences(Long wordid) {

		try {
			return iWordsSearchService.searchSentences(wordid, 0, 100);
		} catch (Exception e) {
			log.error("Lucene查询所有例句出错", e);
		}
		return Collections.EMPTY_LIST;
	}

}
